package mutilthread;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

public class Config {

	private String PROPERTIES_FILE = "";

	// 读取properties的全部信息
	private void readProperties() {
		Properties props = new Properties();
		try {
			// InputStream in = new BufferedInputStream(new FileInputStream(ud +
			// File.separator + PROPERTIES_FILE));
			InputStream in = new BufferedInputStream(new FileInputStream(PROPERTIES_FILE));
			props.load(in);
			Enumeration en = props.propertyNames();
			while (en.hasMoreElements()) {
				String key = (String) en.nextElement();
				String Property = props.getProperty(key);
				System.out.println(key + Property);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// ////////////根据key读取value
	public String readValue(String key, String defaultvalue) {
		String t = readValue(key);
		return t == null ? defaultvalue : t;
	}

	// ////////////根据key读取value
	private String readValue(String key) {
		Properties props = new Properties();
		try {
			// InputStream in = new BufferedInputStream(new FileInputStream(ud +
			// File.separator + PROPERTIES_FILE));
			InputStream in = new BufferedInputStream(new FileInputStream(PROPERTIES_FILE));
			props.load(in);
			String value = props.getProperty(key);
			System.out.println(key + "=" + value);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public Config(String s) {
		this.PROPERTIES_FILE = s;
	}

	// public static void main(String[] args) {
	// Config dao = new Config("");
	//
	// String aaa = dao.readValue("HOST");
	//
	// // System.out.println("====>aaa=" + aaa);
	//
	// }

}
